<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>final: Fichero Fuente C:/Documents and Settings/HP Pavilion zv/My Documents/MER/Facultad/Sisem/LOCALIZADOR/Doxygen 2/mainNC.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generado por Doxygen 1.5.9 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Página&nbsp;principal</span></a></li>
      <li><a href="annotated.html"><span>Estructuras&nbsp;de&nbsp;Datos</span></a></li>
      <li class="current"><a href="files.html"><span>Archivos</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>Lista&nbsp;de&nbsp;archivos</span></a></li>
      <li><a href="globals.html"><span>Globales</span></a></li>
    </ul>
  </div>
<h1>C:/Documents and Settings/HP Pavilion zv/My Documents/MER/Facultad/Sisem/LOCALIZADOR/Doxygen 2/mainNC.c</h1><a href="main_n_c_8c.html">Ir a la documentación de este archivo.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include "bsp.h"</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include "mrfi.h"</span>
<a name="l00003"></a>00003 <span class="preprocessor">#include "bsp_leds.h"</span>
<a name="l00004"></a>00004 <span class="preprocessor">#include "bsp_buttons.h"</span>
<a name="l00005"></a>00005 <span class="preprocessor">#include "nwk_types.h"</span>
<a name="l00006"></a>00006 <span class="preprocessor">#include "nwk_api.h"</span>
<a name="l00007"></a>00007 <span class="preprocessor">#include "nwk_frame.h"</span>
<a name="l00008"></a>00008 <span class="preprocessor">#include "nwk.h"</span>
<a name="l00009"></a>00009 <span class="preprocessor">#include "<a class="code" href="vlo__rand_8h.html">vlo_rand.h</a>"</span>
<a name="l00010"></a>00010 <span class="preprocessor">#include "cod_errores.h"</span>
<a name="l00011"></a>00011 <span class="preprocessor">#include "<a class="code" href="_calc_pos_8h.html">CalcPos.h</a>"</span>
<a name="l00012"></a>00012 <span class="preprocessor">#include "<a class="code" href="tabla_8h.html">tabla.h</a>"</span>
<a name="l00013"></a>00013 
<a name="l00014"></a>00014 
<a name="l00015"></a>00015 <span class="keywordtype">void</span> <a class="code" href="main_n_c_8c.html#1e3b6d38df0786ccf7f938d60e386aae">Init</a>();
<a name="l00016"></a>00016 <span class="keywordtype">void</span> <a class="code" href="main_n_c_8c.html#3edbadacbe8d30476d45c759761a7789">TXString</a>( <span class="keywordtype">char</span>* cadena, <span class="keywordtype">int</span> largo );
<a name="l00017"></a>00017 
<a name="l00020"></a>00020 <span class="keyword">static</span>          linkID_t sLinkIDX = 0;
<a name="l00021"></a>00021 <span class="keyword">static</span>          linkID_t sLinkIDA = 0;
<a name="l00022"></a>00022 <span class="keyword">static</span>          linkID_t sLinkIDB = 0;
<a name="l00023"></a>00023 
<a name="l00024"></a>00024 
<a name="l00025"></a>00025 <span class="keyword">static</span>          uint8_t  sRxTid = 0;
<a name="l00026"></a>00026 <span class="keyword">static</span>          <span class="keywordtype">char</span> comandoSerie = 0;
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 <span class="keyword">static</span> uint8_t sRxCallback(linkID_t port);
<a name="l00029"></a>00029 
<a name="l00030"></a>00030 
<a name="l00031"></a>00031 <span class="comment">// main del nodo central</span>
<a name="l00032"></a>00032 <span class="comment">// </span>
<a name="l00033"></a><a class="code" href="main_n_c_8c.html#840291bc02cba5474a4cb46a9b9566fe">00033</a> <span class="keywordtype">int</span> <a class="code" href="main_n_c_8c.html#840291bc02cba5474a4cb46a9b9566fe">main</a>( <span class="keywordtype">void</span> )
<a name="l00034"></a>00034 {
<a name="l00035"></a>00035   <span class="comment">// Stop watchdog timer to prevent time out reset</span>
<a name="l00036"></a>00036   WDTCTL = WDTPW + WDTHOLD;
<a name="l00037"></a>00037   
<a name="l00038"></a>00038   <a class="code" href="main_n_c_8c.html#1e3b6d38df0786ccf7f938d60e386aae">Init</a>();
<a name="l00039"></a>00039   
<a name="l00040"></a>00040   
<a name="l00041"></a>00041   
<a name="l00042"></a>00042   <span class="comment">// inicializo el kit</span>
<a name="l00043"></a>00043   BSP_Init();
<a name="l00044"></a>00044   
<a name="l00045"></a>00045   
<a name="l00046"></a>00046   <a class="code" href="main_n_c_8c.html#3edbadacbe8d30476d45c759761a7789">TXString</a>(<span class="stringliteral">"Tracking v0.1\n"</span>,15);
<a name="l00047"></a>00047   
<a name="l00048"></a>00048   
<a name="l00049"></a>00049   <span class="comment">// levanto la radio -----------------------------------------------</span>
<a name="l00050"></a>00050   addr_t lAddr;
<a name="l00051"></a>00051   
<a name="l00052"></a>00052   <span class="comment">// direccion del nodo central!!!!</span>
<a name="l00053"></a>00053   lAddr.addr[0]=0xAC; <span class="comment">// nodo central</span>
<a name="l00054"></a>00054   lAddr.addr[1]=0;
<a name="l00055"></a>00055   lAddr.addr[2]=0;
<a name="l00056"></a>00056   lAddr.addr[3]=10;
<a name="l00057"></a>00057   <span class="comment">// ------------------------------</span>
<a name="l00058"></a>00058   <span class="comment">// seteo la direccion del modulo</span>
<a name="l00059"></a>00059   <span class="comment">// OJO que hay que reprogramar!!!!</span>
<a name="l00060"></a>00060   SMPL_Ioctl(IOCTL_OBJ_ADDR, IOCTL_ACT_SET, &amp;lAddr);
<a name="l00061"></a>00061   
<a name="l00062"></a>00062   
<a name="l00063"></a>00063   <span class="comment">// esta llamada devuelve un fail, porque no es la idea que levante nada</span>
<a name="l00064"></a>00064   <span class="comment">// asi que ni la chequeo...</span>
<a name="l00065"></a>00065   SMPL_Init(sRxCallback);
<a name="l00066"></a>00066   
<a name="l00067"></a>00067   
<a name="l00068"></a>00068   <span class="comment">// termine de levantar la radio</span>
<a name="l00069"></a>00069   <a class="code" href="main_n_c_8c.html#3edbadacbe8d30476d45c759761a7789">TXString</a>(<span class="stringliteral">"Inicializacion finalizada\r\n"</span>,27);
<a name="l00070"></a>00070   
<a name="l00071"></a>00071   <span class="comment">// contador para saber cuantas conexiones tengo y parar cuando llego a</span>
<a name="l00072"></a>00072   <span class="comment">// 3 conexiones, mas adelante va a ser en distinto orden.</span>
<a name="l00073"></a>00073   <span class="keywordtype">int</span> conexiones = 0;
<a name="l00074"></a>00074   
<a name="l00075"></a>00075   <span class="keywordflow">while</span> (conexiones&lt;3)
<a name="l00076"></a>00076   {
<a name="l00077"></a>00077     <span class="keywordflow">switch</span>(conexiones){
<a name="l00078"></a>00078     <span class="keywordflow">case</span> 0: 
<a name="l00079"></a>00079       <span class="comment">// el nodo central busca al nodo A</span>
<a name="l00080"></a>00080       <span class="keywordflow">if</span> (SMPL_SUCCESS == SMPL_Link(&amp;sLinkIDA))   
<a name="l00081"></a>00081       {
<a name="l00082"></a>00082         conexiones++;
<a name="l00083"></a>00083       }
<a name="l00084"></a>00084       <span class="keywordflow">break</span>;
<a name="l00085"></a>00085     <span class="keywordflow">case</span> 1:
<a name="l00086"></a>00086       <span class="comment">// el nodo central busca al nodo B</span>
<a name="l00087"></a>00087       <span class="keywordflow">if</span> (SMPL_SUCCESS == SMPL_Link(&amp;sLinkIDB))   
<a name="l00088"></a>00088       {
<a name="l00089"></a>00089         conexiones++;
<a name="l00090"></a>00090       }
<a name="l00091"></a>00091       <span class="keywordflow">break</span>;
<a name="l00092"></a>00092     <span class="keywordflow">case</span> 2:
<a name="l00093"></a>00093       <span class="comment">// el nodo central busca al nodo X</span>
<a name="l00094"></a>00094       <span class="keywordflow">if</span> (SMPL_SUCCESS == SMPL_Link(&amp;sLinkIDX))   
<a name="l00095"></a>00095       {
<a name="l00096"></a>00096         conexiones++;
<a name="l00097"></a>00097       }
<a name="l00098"></a>00098       <span class="keywordflow">break</span>; 
<a name="l00099"></a>00099     <span class="keywordflow">default</span>:
<a name="l00100"></a>00100       <span class="keywordflow">break</span>;
<a name="l00101"></a>00101     }
<a name="l00102"></a>00102     BSP_TOGGLE_LED1(); <span class="comment">// hago parpadear el led para ver que esta haciendo</span>
<a name="l00103"></a>00103     <span class="comment">// (algo mas corto que mandar un warning)</span>
<a name="l00104"></a>00104   }
<a name="l00105"></a>00105   
<a name="l00106"></a>00106   <span class="comment">// hay conexion</span>
<a name="l00107"></a>00107   signalError(0);
<a name="l00108"></a>00108   
<a name="l00109"></a>00109   
<a name="l00110"></a>00110   <span class="comment">/*</span>
<a name="l00111"></a>00111 <span class="comment">  uint8_t     msg[MAX_APP_PAYLOAD], len;</span>
<a name="l00112"></a>00112 <span class="comment">  </span>
<a name="l00113"></a>00113 <span class="comment">  msg[0] = 't';</span>
<a name="l00114"></a>00114 <span class="comment">  msg[1] = 'x';</span>
<a name="l00115"></a>00115 <span class="comment">  msg[2] = 'N';</span>
<a name="l00116"></a>00116 <span class="comment">  msg[3] = 'C';</span>
<a name="l00117"></a>00117 <span class="comment">  </span>
<a name="l00118"></a>00118 <span class="comment">  len = 4;</span>
<a name="l00119"></a>00119 <span class="comment">  </span>
<a name="l00120"></a>00120 <span class="comment">  // EMPIEZA EL PROTOCOLO PROPIAMENTE DICHO!</span>
<a name="l00121"></a>00121 <span class="comment">  if(SMPL_SUCCESS == SMPL_Send(sLinkIDX,msg,len)){</span>
<a name="l00122"></a>00122 <span class="comment">    signalError(0);    </span>
<a name="l00123"></a>00123 <span class="comment">  }</span>
<a name="l00124"></a>00124 <span class="comment">  else{</span>
<a name="l00125"></a>00125 <span class="comment">    signalError(4);</span>
<a name="l00126"></a>00126 <span class="comment">  }</span>
<a name="l00127"></a>00127 <span class="comment">  </span>
<a name="l00128"></a>00128 <span class="comment">  len = 0;</span>
<a name="l00129"></a>00129 <span class="comment">  */</span>
<a name="l00130"></a>00130   
<a name="l00131"></a>00131   <span class="comment">// no vuelve nunca mas</span>
<a name="l00132"></a>00132   <a class="code" href="main_n_c_8c.html#3241a2beddab65e0899bf27f90cacece">systemStart</a>();
<a name="l00133"></a>00133   
<a name="l00134"></a>00134   <span class="keywordflow">return</span> 0;
<a name="l00135"></a>00135 }
<a name="l00136"></a>00136 
<a name="l00138"></a><a class="code" href="main_n_c_8c.html#e248ff6080191b4ce858dc8f7e3477de">00138</a> <span class="keywordtype">char</span> <a class="code" href="main_n_c_8c.html#e248ff6080191b4ce858dc8f7e3477de">espero</a> = 1;
<a name="l00139"></a>00139 
<a name="l00142"></a><a class="code" href="main_n_c_8c.html#1966891e271d96bc4fd35f1a0d92185e">00142</a> <span class="keywordtype">char</span> <a class="code" href="main_n_c_8c.html#1966891e271d96bc4fd35f1a0d92185e">largoMsgX</a> = 0;
<a name="l00143"></a><a class="code" href="main_n_c_8c.html#b8b07b512ea5f779e5b9ef125aae2cc0">00143</a> <span class="keywordtype">char</span> <a class="code" href="main_n_c_8c.html#b8b07b512ea5f779e5b9ef125aae2cc0">largoMsgA</a> = 0;
<a name="l00144"></a><a class="code" href="main_n_c_8c.html#ce663b6ad1377f765534ea1167f28180">00144</a> <span class="keywordtype">char</span> <a class="code" href="main_n_c_8c.html#ce663b6ad1377f765534ea1167f28180">largoMsgB</a> = 0;
<a name="l00145"></a>00145 
<a name="l00148"></a><a class="code" href="main_n_c_8c.html#ed6d4aaee3ff8ee345eeeae300f5f0eb">00148</a> <span class="keywordtype">char</span>[MAX_APP_PAYLOAD] <a class="code" href="main_n_c_8c.html#ed6d4aaee3ff8ee345eeeae300f5f0eb">msgA</a>;
<a name="l00149"></a><a class="code" href="main_n_c_8c.html#98efee00decef955550f6a706b05d154">00149</a> <span class="keywordtype">char</span>[MAX_APP_PAYLOAD] <a class="code" href="main_n_c_8c.html#98efee00decef955550f6a706b05d154">msgB</a>;
<a name="l00150"></a><a class="code" href="main_n_c_8c.html#4ae96a19335f191f869bf5279850b69f">00150</a> <span class="keywordtype">char</span>[MAX_APP_PAYLOAD] <a class="code" href="main_n_c_8c.html#4ae96a19335f191f869bf5279850b69f">msgX</a>;
<a name="l00151"></a>00151 
<a name="l00152"></a>00152 <span class="comment">//-------------------------------------------------------------------</span>
<a name="l00153"></a>00153 <span class="comment">// Inicio el sistema</span>
<a name="l00159"></a><a class="code" href="_n_m_b_8c.html#3241a2beddab65e0899bf27f90cacece">00159</a> <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="main_n_c_8c.html#3241a2beddab65e0899bf27f90cacece">systemStart</a>(){
<a name="l00160"></a>00160   
<a name="l00161"></a>00161   <span class="keywordflow">while</span>(1)
<a name="l00162"></a>00162   {
<a name="l00163"></a>00163     <span class="comment">// espero a que inicien el sistema con un comando,</span>
<a name="l00164"></a>00164     <span class="comment">// o con el boton.  </span>
<a name="l00165"></a>00165     clearError();
<a name="l00166"></a>00166     <span class="keywordflow">while</span>(1){
<a name="l00167"></a>00167       <span class="keywordflow">if</span>(BSP_BUTTON1() || comandoSerie){
<a name="l00168"></a>00168         signalError(1);
<a name="l00169"></a>00169         <span class="keywordflow">break</span>;
<a name="l00170"></a>00170       }
<a name="l00171"></a>00171     }
<a name="l00172"></a>00172     
<a name="l00173"></a>00173     <span class="comment">// me llamaron e intento ubicar a los nodos para pedir info</span>
<a name="l00174"></a>00174     <span class="comment">// empiezo por el X</span>
<a name="l00175"></a>00175     
<a name="l00176"></a>00176     <span class="keywordtype">char</span>[] msg = <span class="stringliteral">"WKUP"</span>; <span class="comment">// mensaje de despertarse</span>
<a name="l00177"></a>00177     <span class="comment">// round robin con interrupciones</span>
<a name="l00178"></a>00178     <span class="comment">// espero que me conteste</span>
<a name="l00179"></a>00179     <span class="keywordflow">while</span>(!<a class="code" href="main_n_c_8c.html#1966891e271d96bc4fd35f1a0d92185e">largoMsgX</a>){
<a name="l00180"></a>00180       SMPL_SUCCESS == SMPL_Send(sLinkIDX,msg,len);
<a name="l00181"></a>00181     }
<a name="l00182"></a>00182     <span class="keywordflow">while</span>(!<a class="code" href="main_n_c_8c.html#b8b07b512ea5f779e5b9ef125aae2cc0">largoMsgA</a>){
<a name="l00183"></a>00183       SMPL_SUCCESS == SMPL_Send(sLinkIDA,msg,len);
<a name="l00184"></a>00184     }
<a name="l00185"></a>00185     <span class="keywordflow">while</span>(!<a class="code" href="main_n_c_8c.html#ce663b6ad1377f765534ea1167f28180">largoMsgB</a>){
<a name="l00186"></a>00186       SMPL_SUCCESS == SMPL_Send(sLinkIDB,msg,len);
<a name="l00187"></a>00187     }
<a name="l00188"></a>00188     
<a name="l00189"></a>00189     
<a name="l00190"></a>00190     <span class="comment">// Recolecte la info, ahora tengo que calcular y mostrar</span>
<a name="l00191"></a>00191     <a class="code" href="main_n_c_8c.html#5cfdf506a309802e07cbfd0ca5346d70">localizar</a>(<a class="code" href="tabla_8c.html#a31734ed693ccb753a16705b2e36602c">RSSIAMETRO</a>(rssi_intX), <a class="code" href="tabla_8c.html#a31734ed693ccb753a16705b2e36602c">RSSIAMETRO</a>(rssi_intA), 
<a name="l00192"></a>00192               <a class="code" href="tabla_8c.html#a31734ed693ccb753a16705b2e36602c">RSSIAMETRO</a>(rssi_intB));
<a name="l00193"></a>00193     
<a name="l00194"></a>00194     
<a name="l00195"></a>00195   }  
<a name="l00196"></a>00196 }
<a name="l00197"></a>00197 
<a name="l00198"></a>00198 <span class="comment">//-------------------------------------------------------------------</span>
<a name="l00199"></a>00199 <span class="comment">//</span>
<a name="l00200"></a><a class="code" href="_n_m_b_8c.html#5cfdf506a309802e07cbfd0ca5346d70">00200</a> <span class="keywordtype">void</span> <a class="code" href="main_n_c_8c.html#5cfdf506a309802e07cbfd0ca5346d70">localizar</a>(<span class="keywordtype">float</span> distX,<span class="keywordtype">float</span> distA, <span class="keywordtype">float</span> distB){
<a name="l00201"></a>00201 
<a name="l00202"></a>00202   <a class="code" href="main_n_c_8c.html#3edbadacbe8d30476d45c759761a7789">TXString</a>(<span class="stringliteral">"X:"</span>,2);  
<a name="l00203"></a>00203   <a class="code" href="main_n_c_8c.html#3edbadacbe8d30476d45c759761a7789">TXString</a>(<a class="code" href="main_n_c_8c.html#d4defa2786c2b618c997435250a05f70">float2String</a>(),4);
<a name="l00204"></a>00204   
<a name="l00205"></a>00205   <a class="code" href="main_n_c_8c.html#3edbadacbe8d30476d45c759761a7789">TXString</a>(<span class="stringliteral">"Y:"</span>,2);  
<a name="l00206"></a>00206   <a class="code" href="main_n_c_8c.html#3edbadacbe8d30476d45c759761a7789">TXString</a>(<a class="code" href="main_n_c_8c.html#d4defa2786c2b618c997435250a05f70">float2String</a>(),4);
<a name="l00207"></a>00207   
<a name="l00208"></a>00208   <a class="code" href="main_n_c_8c.html#3edbadacbe8d30476d45c759761a7789">TXString</a>(<span class="stringliteral">"\n\r"</span>,2); 
<a name="l00209"></a>00209 }
<a name="l00210"></a>00210 
<a name="l00213"></a><a class="code" href="_n_m_b_8c.html#d4defa2786c2b618c997435250a05f70">00213</a> <span class="keywordtype">char</span>* <a class="code" href="main_n_c_8c.html#d4defa2786c2b618c997435250a05f70">float2String</a>(<span class="keywordtype">float</span> numero){
<a name="l00214"></a>00214   
<a name="l00215"></a>00215     <span class="keywordtype">char</span>* result = <span class="stringliteral">"xx.x"</span><span class="stringliteral">";</span>
<a name="l00216"></a>00216 <span class="stringliteral">    int nro = 10*numero;</span>
<a name="l00217"></a>00217 <span class="stringliteral"></span>
<a name="l00218"></a>00218 <span class="stringliteral">    result[3] = '0'+nro%10;</span>
<a name="l00219"></a>00219 <span class="stringliteral">    result[1] = '0'+(nro/10)%10;</span>
<a name="l00220"></a>00220 <span class="stringliteral">    result[0] = '0'+(nro/100)%10;</span>
<a name="l00221"></a>00221 <span class="stringliteral">  </span>
<a name="l00222"></a>00222 <span class="stringliteral">  return result;</span>
<a name="l00223"></a>00223 <span class="stringliteral">}</span>
<a name="l00224"></a>00224 <span class="stringliteral"></span>
<a name="l00225"></a>00225 <span class="stringliteral">// ------------------------------------------------------------------</span>
<a name="l00226"></a>00226 <span class="stringliteral">// transmito por el puerto serie</span>
<a name="l00227"></a>00227 <span class="stringliteral">//</span>
<a name="l00234"></a>00234 <span class="stringliteral">void TXString( char* cadena, int largo )</span>
<a name="l00235"></a>00235 <span class="stringliteral">{</span>
<a name="l00236"></a>00236 <span class="stringliteral">  int puntero;</span>
<a name="l00237"></a>00237 <span class="stringliteral">  for( puntero = 0; puntero &lt; largo; puntero++){</span>
<a name="l00238"></a>00238 <span class="stringliteral">    UCA0TXBUF = cadena[puntero];</span>
<a name="l00239"></a>00239 <span class="stringliteral">    while (!(IFG2&amp;UCA0TXIFG));              // espero a que termine de enviar</span>
<a name="l00240"></a>00240 <span class="stringliteral">  }</span>
<a name="l00241"></a>00241 <span class="stringliteral">}</span>
<a name="l00242"></a>00242 <span class="stringliteral"></span>
<a name="l00243"></a>00243 <span class="stringliteral"></span>
<a name="l00247"></a>00247 <span class="stringliteral">static int rssi_intX;</span>
<a name="l00248"></a>00248 <span class="stringliteral">static int rssi_intA;</span>
<a name="l00249"></a>00249 <span class="stringliteral">static int rssi_intB;</span>
<a name="l00250"></a>00250 <span class="stringliteral"></span>
<a name="l00251"></a>00251 <span class="stringliteral">// -------------------------------------------------</span>
<a name="l00256"></a>00256 <span class="stringliteral">static uint8_t sRxCallback(linkID_t port){</span>
<a name="l00257"></a>00257 <span class="stringliteral">  uint8_t msg[MAX_APP_PAYLOAD], len;</span>
<a name="l00258"></a>00258 <span class="stringliteral">  len = 0;</span>
<a name="l00259"></a>00259 <span class="stringliteral">    ioctlRadioSiginfo_t sigInfo;</span>
<a name="l00260"></a>00260 <span class="stringliteral">    char rssiString[3];</span>
<a name="l00261"></a>00261 <span class="stringliteral">    volatile signed int rssi_int;</span>
<a name="l00262"></a>00262 <span class="stringliteral">    signed char rssi;</span>
<a name="l00263"></a>00263 <span class="stringliteral">  // manejo el mensaje dependiendo de quien lo envia</span>
<a name="l00264"></a>00264 <span class="stringliteral">  if (port == sLinkIDX)</span>
<a name="l00265"></a>00265 <span class="stringliteral">  {</span>
<a name="l00266"></a>00266 <span class="stringliteral">    // si recibo un paquete de largo mayor que 0</span>
<a name="l00267"></a>00267 <span class="stringliteral">    if ((SMPL_SUCCESS == SMPL_Receive(sLinkIDX, msg, &amp;len)) &amp;&amp; len)</span>
<a name="l00268"></a>00268 <span class="stringliteral">    {</span>
<a name="l00269"></a>00269 <span class="stringliteral">      sigInfo.lid = sLinkIDX;</span>
<a name="l00270"></a>00270 <span class="stringliteral">      SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SIGINFO, (void *)&amp;sigInfo);</span>
<a name="l00271"></a>00271 <span class="stringliteral">      rssi = (signed char)sigInfo.sigInfo[0];</span>
<a name="l00272"></a>00272 <span class="stringliteral">      rssi_intX = (signed int) rssi;</span>
<a name="l00273"></a>00273 <span class="stringliteral">      rssi_intX += 128;</span>
<a name="l00274"></a>00274 <span class="stringliteral">      largoMsgX = len;</span>
<a name="l00275"></a>00275 <span class="stringliteral">      // guardo el mensaje</span>
<a name="l00276"></a>00276 <span class="stringliteral">      copiarArray(msg,msgX,len);</span>
<a name="l00277"></a>00277 <span class="stringliteral"></span>
<a name="l00278"></a>00278 <span class="stringliteral">      </span>
<a name="l00279"></a>00279 <span class="stringliteral">//      rssiString[2] = '0'+(rssi_int%10);</span>
<a name="l00280"></a>00280 <span class="stringliteral">//      rssiString[1] = '0'+((rssi_int/10)%10);</span>
<a name="l00281"></a>00281 <span class="stringliteral">//      rssiString[0] = '0'+((rssi_int/100)%10);</span>
<a name="l00282"></a>00282 <span class="stringliteral">    }</span>
<a name="l00283"></a>00283 <span class="stringliteral">  }</span>
<a name="l00284"></a>00284 <span class="stringliteral">  else if(port == sLinkIDA){</span>
<a name="l00285"></a>00285 <span class="stringliteral">    if ((SMPL_SUCCESS == SMPL_Receive(sLinkIDA, msg, &amp;len)) &amp;&amp; len)</span>
<a name="l00286"></a>00286 <span class="stringliteral">    {</span>
<a name="l00287"></a>00287 <span class="stringliteral">      sigInfo.lid = sLinkIDA;</span>
<a name="l00288"></a>00288 <span class="stringliteral">      SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SIGINFO, (void *)&amp;sigInfo);</span>
<a name="l00289"></a>00289 <span class="stringliteral">      rssi = (signed char)sigInfo.sigInfo[0];</span>
<a name="l00290"></a>00290 <span class="stringliteral">      rssi_intA = (signed int) rssi;</span>
<a name="l00291"></a>00291 <span class="stringliteral">      rssi_intA += 128;</span>
<a name="l00292"></a>00292 <span class="stringliteral">      largoMsgA = len;</span>
<a name="l00293"></a>00293 <span class="stringliteral">    }</span>
<a name="l00294"></a>00294 <span class="stringliteral">  }</span>
<a name="l00295"></a>00295 <span class="stringliteral">  else if(port == sLinkIDB){</span>
<a name="l00296"></a>00296 <span class="stringliteral">    if ((SMPL_SUCCESS == SMPL_Receive(sLinkIDB, msg, &amp;len)) &amp;&amp; len)</span>
<a name="l00297"></a>00297 <span class="stringliteral">    {</span>
<a name="l00298"></a>00298 <span class="stringliteral">      sigInfo.lid = sLinkIDB;</span>
<a name="l00299"></a>00299 <span class="stringliteral">      SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SIGINFO, (void *)&amp;sigInfo);</span>
<a name="l00300"></a>00300 <span class="stringliteral">      rssi = (signed char)sigInfo.sigInfo[0];</span>
<a name="l00301"></a>00301 <span class="stringliteral">      rssi_intB = (signed int) rssi;</span>
<a name="l00302"></a>00302 <span class="stringliteral">      rssi_intB += 128;</span>
<a name="l00303"></a>00303 <span class="stringliteral">      largoMsgB = len;</span>
<a name="l00304"></a>00304 <span class="stringliteral">    }</span>
<a name="l00305"></a>00305 <span class="stringliteral">  }</span>
<a name="l00306"></a>00306 <span class="stringliteral"></span>
<a name="l00307"></a>00307 <span class="stringliteral">  // libero el frame porque lo use aca...</span>
<a name="l00308"></a>00308 <span class="stringliteral">  // guardo el ultimo mensaje, la unica opcion de que me envien</span>
<a name="l00309"></a>00309 <span class="stringliteral">  // mas mensajes es que sean de WKUP y eso pasa solo en los nodos</span>
<a name="l00310"></a>00310 <span class="stringliteral">  // moviles.</span>
<a name="l00311"></a>00311 <span class="stringliteral">  // Como el codigo que ejecuta es corto lo dejo en el contexto</span>
<a name="l00312"></a>00312 <span class="stringliteral">  // de la ISR</span>
<a name="l00313"></a>00313 <span class="stringliteral">  return 1;</span>
<a name="l00314"></a>00314 <span class="stringliteral">}</span>
<a name="l00315"></a>00315 <span class="stringliteral"></span>
<a name="l00320"></a>00320 <span class="stringliteral">void copiarArray(char* origen,char* destino, int largo ){</span>
<a name="l00321"></a>00321 <span class="stringliteral"></span>
<a name="l00322"></a>00322 <span class="stringliteral">        for(int i=0;i&lt;largo;i++){</span>
<a name="l00323"></a>00323 <span class="stringliteral">                destino[i] = origen[i];</span>
<a name="l00324"></a>00324 <span class="stringliteral">        }</span>
<a name="l00325"></a>00325 <span class="stringliteral">}</span>
<a name="l00326"></a>00326 <span class="stringliteral">//---------------------------------------------------------------------------</span>
<a name="l00330"></a>00330 <span class="stringliteral">void Init()</span>
<a name="l00331"></a>00331 <span class="stringliteral">{</span>
<a name="l00332"></a>00332 <span class="stringliteral">  // SimpliciTI igual los cambia...</span>
<a name="l00333"></a>00333 <span class="stringliteral">  P1DIR = 0xFB;</span>
<a name="l00334"></a>00334 <span class="stringliteral">  P1OUT = 0x00;</span>
<a name="l00335"></a>00335 <span class="stringliteral">  P2DIR = 0x27;</span>
<a name="l00336"></a>00336 <span class="stringliteral">  P2OUT = 0x00;</span>
<a name="l00337"></a>00337 <span class="stringliteral">  P3DIR = 0xC0;</span>
<a name="l00338"></a>00338 <span class="stringliteral">  P3OUT = 0x00;</span>
<a name="l00339"></a>00339 <span class="stringliteral">  P4DIR = 0xFF;</span>
<a name="l00340"></a>00340 <span class="stringliteral">  P4OUT = 0x00;</span>
<a name="l00341"></a>00341 <span class="stringliteral">  </span>
<a name="l00342"></a>00342 <span class="stringliteral">  </span>
<a name="l00343"></a>00343 <span class="stringliteral">  </span>
<a name="l00344"></a>00344 <span class="stringliteral">  BCSCTL1 = CALBC1_8MHZ;                    // Set DCO</span>
<a name="l00345"></a>00345 <span class="stringliteral">  DCOCTL = CALDCO_8MHZ;</span>
<a name="l00346"></a>00346 <span class="stringliteral">  </span>
<a name="l00347"></a>00347 <span class="stringliteral">  BCSCTL3 |= LFXT1S_2;                      // LFXT1 = VLO</span>
<a name="l00348"></a>00348 <span class="stringliteral">  TACCTL0 = CCIE;                           // TACCR0 IE</span>
<a name="l00349"></a>00349 <span class="stringliteral">  TACCR0 = 12000;                           // aprox un seg</span>
<a name="l00350"></a>00350 <span class="stringliteral">  TACTL = TASSEL_1 + MC_1;                  // ACLK, upmode</span>
<a name="l00351"></a>00351 <span class="stringliteral">  </span>
<a name="l00352"></a>00352 <span class="stringliteral">  P3SEL |= 0x30;                            // P3.4,5 = USCI_A0 TXD/RXD</span>
<a name="l00353"></a>00353 <span class="stringliteral">  UCA0CTL1 = UCSSEL_2;                      // SMCLK</span>
<a name="l00354"></a>00354 <span class="stringliteral">  UCA0BR0 = 0x41;                           // 9600 a 8Mhz</span>
<a name="l00355"></a>00355 <span class="stringliteral">  UCA0BR1 = 0x3;</span>
<a name="l00356"></a>00356 <span class="stringliteral">  UCA0MCTL = UCBRS_2;                       </span>
<a name="l00357"></a>00357 <span class="stringliteral">  UCA0CTL1 &amp;= ~UCSWRST;                     // **Initialize USCI state achine**</span>
<a name="l00358"></a>00358 <span class="stringliteral">  IE2 |= UCA0RXIE;                          // Enable USCI_A0 RX interrupt</span>
<a name="l00359"></a>00359 <span class="stringliteral">  __enable_interrupt(); </span>
<a name="l00360"></a>00360 <span class="stringliteral">}</span>
<a name="l00361"></a>00361 <span class="stringliteral"></span>
<a name="l00362"></a>00362 <span class="stringliteral">//---------------------------------------------------------------------/** Timer A0 ISR</span>
<a name="l00363"></a>00363 <span class="stringliteral">*/</span>
<a name="l00364"></a>00364 <span class="stringliteral">#pragma vector=TIMERA0_VECTOR</span>
<a name="l00365"></a>00365 <span class="stringliteral">__interrupt void Timer_A (void)</span>
<a name="l00366"></a>00366 <span class="stringliteral">{</span>
<a name="l00367"></a>00367 <span class="stringliteral">  // la idea era dormirse despues de x tiempo</span>
<a name="l00368"></a>00368 <span class="stringliteral">}</span>
<a name="l00369"></a>00369 <span class="stringliteral"></span>
<a name="l00370"></a>00370 <span class="stringliteral"></span>
<a name="l00372"></a>00372 <span class="stringliteral">*/</span>
<a name="l00373"></a>00373 <span class="stringliteral">#pragma vector=USCIAB0RX_VECTOR</span>
<a name="l00374"></a>00374 <span class="stringliteral">__interrupt void USCI0RX_ISR(void)</span>
<a name="l00375"></a>00375 <span class="stringliteral">{</span>
<a name="l00376"></a>00376 <span class="stringliteral">  </span>
<a name="l00377"></a>00377 <span class="stringliteral">  // me preparo para recibir comandos...</span>
<a name="l00378"></a>00378 <span class="stringliteral">  </span>
<a name="l00379"></a>00379 <span class="stringliteral">  char rx = UCA0RXBUF;</span>
<a name="l00380"></a>00380 <span class="stringliteral">  if ( rx == 'b' || rx == 'B' )  // buscar nodo</span>
<a name="l00381"></a>00381 <span class="stringliteral">  {</span>
<a name="l00382"></a>00382 <span class="stringliteral">    comandoSerie = rx;</span>
<a name="l00383"></a>00383 <span class="stringliteral">  }</span>
<a name="l00384"></a>00384 <span class="stringliteral">  else if ( rx == 'S' || rx == 's' ) // S iempre encendido</span>
<a name="l00385"></a>00385 <span class="stringliteral">  {</span>
<a name="l00386"></a>00386 <span class="stringliteral">  }</span>
<a name="l00387"></a>00387 <span class="stringliteral">  else if ( rx == 'A' || rx == 'a' ) // A pagar, o A dormir</span>
<a name="l00388"></a>00388 <span class="stringliteral">  {</span>
<a name="l00389"></a>00389 <span class="stringliteral">  }</span>
<a name="l00390"></a>00390 <span class="stringliteral">  </span>
<a name="l00391"></a>00391 <span class="stringliteral">  </span>
<a name="l00392"></a>00392 <span class="stringliteral">}</span>
<a name="l00393"></a>00393 <span class="stringliteral"></span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generado el Mon Jun 22 08:40:32 2009 para final por&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address>
</body>
</html>
